using System;
using UnityEngine;
using UnityEngine.UI;public class LevelManager: MonoBehaviour
{
        public 调酒系统 调酒系统;
        public DialogSystem dialogSystem;
        public 剧情演出系统 剧情演出系统;

        private string command;
        private string name;
        private string previousCommand = "";

        private bool isIn调酒ing = false;
        void Update()
        {
                string currentCommand = dialogSystem.GetCommand();
                if (currentCommand != null && currentCommand != previousCommand)
                {
                        previousCommand = currentCommand; 
                        string[] tmp = currentCommand.Split(',');
                        command = tmp[0];
                        name = tmp[1];
            
                        CommandSwitch();
                }
                
                调酒();
        }

        private void CommandSwitch()
        {
                switch (command)
                {
                        case "调酒请求":
                                调酒系统.SetWine(name);
                                dialogSystem.PauseDialog(true);
                                isIn调酒ing = true;
                                break;
                        case "背景设置":
                                剧情演出系统.SetImage("background", name); 
                                break;
                        case "左侧角色":
                                剧情演出系统.SetImage("left", name);
                                break;
                        case "右侧角色":
                                剧情演出系统.SetImage("right", name);
                                break;
                        case "中间角色":
                                剧情演出系统.SetImage("mid", name);
                                break;
                        case "左侧角色消失":
                                剧情演出系统.FadeImage("left");
                                break;
                        case "右侧角色消失":
                                剧情演出系统.FadeImage("right");
                                break;
                        case "中间角色消失":
                                剧情演出系统.FadeImage("mid");
                                break;
                        case "背景消失":
                                剧情演出系统.FadeImage("left");
                                剧情演出系统.FadeImage("right");
                                剧情演出系统.FadeImage("mid");
                                剧情演出系统.FadeImage("background");
                                break;
                        case "淡入淡出":
                                剧情演出系统.FadeScene();
                                break;
                        default:
                                Debug.LogWarning($"Unknown command: {command}");
                                break;
                }

                command = "";
                name = "";
        }

        private void 调酒()
        {
                if (dialogSystem.IsPaused && 调酒系统.IsPassed && isIn调酒ing)
                {
                        isIn调酒ing = false;
                        dialogSystem.PauseDialog(false);
                }
        }
}